using System;
using Glue;
using Glue.Internals;
using GlueTests.Builders;
using Xunit;

namespace GlueTests.AutoRelaterTests
{
    public class When_automatically_relating_properties
    {
        private readonly Mapping<DomainPerson, GuiPerson> mapping;

        public class GuiPerson
        {
            public String FirstName { get; set; }
            public String LastName { get; set; }
            private String PrivateProperty { get; set; }
        }

        public class DomainPerson
        {
            public String FirstName { get; set; }
            public String LastName { get; set; }
            public String UnmappedProperty { get; set; }
            private String PrivateProperty { get; set; }
        }

        public When_automatically_relating_properties()
        {
            mapping = new Mapping<DomainPerson, GuiPerson>();
            mapping.AutoRelateEqualNames();
        }

        [Fact]
        public void Public_properties_with_equal_names_should_be_related()
        {
            Assert.Equal(2, mapping.Relations.Count);
            Assert.True(ContainsOnLeftSide("FirstName"));
            Assert.True(ContainsOnLeftSide("LastName"));
        }

        [Fact]
        public void Properties_without_equals_should_not_be_related()
        {
            Assert.False(ContainsOnLeftSide("UnmappedProperty"));
        }

        [Fact]
        public void Private_properties_should_not_be_related()
        {
            Assert.False(ContainsOnLeftSide("PrivateProperty"));
        }

        private bool ContainsOnLeftSide(String propertyName)
        {
            return mapping.Relations.IsRelatedTowardsOnLeftSide(new PropertyBuilder(typeof(DomainPerson),propertyName).Build());
        }
    }
}